/**
 *  *2010-3-10 下午02:51:32  add 
 */
package com.base.myproject.server.tools;

import java.awt.FlowLayout;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.ResultSet;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import com.base.myproject.server.database.PoolMan;

/**
 * 设计：根据表名，sql语句，主键组织store
 * 
 * @author Administrator 2010-3-10 javazgw@gmail.com
 */
public class MakeStore {

	String tablename, sql;
	String[] key;

	public MakeStore() {

	}

	public String Generation() {
		StringBuffer sbf = new StringBuffer();
		PoolMan pm = new PoolMan();
		try {

			pm.getPool("test");
			ResultSet rs = pm.executeQuery(sql);
			int count = rs.getMetaData().getColumnCount();
			sbf.append("BaseStore<BusiObject> store = null;\n");

			sbf.append("BaseStore<BusiObject> getStore(){\n");
			sbf.append("if(store==null) \n");
			sbf.append("{\n");
			sbf.append("	createStore();\n");
			sbf.append("}\n");
			sbf.append("return store;}\n");

			sbf.append("BaseStore<BusiObject> createStore(){\n");
			sbf.append("ModelType type = new ModelType();\n");
			sbf.append("type.setRoot(\"records\");\n");
			sbf.append("type.setRecordName(\"record\");\n");
			sbf.append("type.setTotalName(\"totle\");\n");
			for (int i = 1; i <= count; i++) {
				/*
				 * System.out.print("1"+rs.getMetaData().getCatalogName(i));
				 * System.out.print("2"+rs.getMetaData().getColumnClassName(i));
				 * System
				 * .out.print("3"+rs.getMetaData().getColumnDisplaySize(i));
				 * System.out.print("4"+rs.getMetaData().getColumnLabel(i));
				 * System.out.print("5"+rs.getMetaData().getColumnName(i));
				 * System.out.print("6"+rs.getMetaData().getColumnType(i));
				 * System.out.print("7"+rs.getMetaData().getColumnTypeName(i));
				 * System.out.print("8"+rs.getMetaData().getPrecision(i));
				 * System.out.print("9"+rs.getMetaData().getScale(i));
				 * System.out.print("10"+rs.getMetaData().getSchemaName(i));
				 * System.out.print("11"+rs.getMetaData().getTableName(i));
				 */

				// System.out.println("-------");

				if (rs.getMetaData().getColumnClassName(i).equals(
						"java.sql.Timestamp")) {
					sbf.append("type.addField(\""
							+ rs.getMetaData().getColumnName(i) + "\");\n");

					sbf.append("type.getField(\""
							+ rs.getMetaData().getColumnName(i)
							+ "\").setType(Date.class);\n");
				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.math.BigDecimal")) {
					sbf.append("type.addField(\""
							+ rs.getMetaData().getColumnName(i) + "\");\n");

					sbf.append("type.getField(\""
							+ rs.getMetaData().getColumnName(i)
							+ "\").setType(Double.class);\n");

				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.Integer")) {
					sbf.append("type.addField(\""
							+ rs.getMetaData().getColumnName(i) + "\");\n");

					sbf.append("type.getField(\""
							+ rs.getMetaData().getColumnName(i)
							+ "\").setType(Integer.class);\n");

				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.Long")) {
					sbf.append("type.addField(\""
							+ rs.getMetaData().getColumnName(i) + "\");\n");

					sbf.append("type.getField(\""
							+ rs.getMetaData().getColumnName(i)
							+ "\").setType(Long.class);\n");

				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.String")) {
					sbf.append("type.addField(\""
							+ rs.getMetaData().getColumnName(i) + "\");\n");

					sbf.append("type.getField(\""
							+ rs.getMetaData().getColumnName(i)
							+ "\").setType(String.class);\n");

				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.Boolean")) {
					sbf.append("type.addField(\""
							+ rs.getMetaData().getColumnName(i) + "\");\n");

					sbf.append("type.getField(\""
							+ rs.getMetaData().getColumnName(i)
							+ "\").setType(Boolean.class);\n");

				} else {
					throw new RuntimeException("不支持的数据类型");
				}

			}

			// StoreInfo info = new StoreInfo();
			// info.setTablename("s_service_po");
			// info.setKeyname(new String[] { "icode" });
			// info.setSql("select * from s_service_po where DATEDIFF(day, getdate(), createdate)=0 and bcode='"+Env.getEnvbcode()+"'");
			//			
			sbf.append("StoreInfo info = new StoreInfo();\n");
			sbf.append("info.setTablename(\"" + tablename + "\");\n");

			String temp = "";
			for (String str : key) {
				temp += "\"" + str + "\",";
			}
			temp = temp.substring(0, temp.length() - 1);
			sbf.append("info.setKeyname(new String[] { " + temp + "});\n");
			sbf.append("info.setSql(\"" + sql + "\");\n");

			sbf.append("//info.setParent(mainstore);// 关联主表\n");
			// info.setAutoinccolumn("idx"); // 自增字段，如果子表一定需要
			sbf
					.append("//info.setLinkparentcolumns(new String[] { \"icode\" }); // 关联主表字段\n");
			sbf
					.append("//info.setLinkparent_chile_columns(new String[] { \"upicode\" });// 关联主表字段\n");

			sbf.append("  store = new BaseStore<BusiObject>(type, info);\n");

			sbf.append(" return store;}\n");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return new String(sbf);
	}

	public String gridGeneraration() {
		StringBuffer sbf = new StringBuffer();
		sbf.append("\n");
		sbf.append("BaseGrid grid=null;\n");
		sbf.append("BaseGrid createGrid(){\n");

		sbf
				.append("CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();\n");
		sbf
				.append("List<ColumnConfig> columns = new ArrayList<ColumnConfig>();\n");
		sbf.append("columns.add(cbs.getColumn());\n");
		sbf.append("\n");

		PoolMan pm = new PoolMan();

		try {
			pm.getPool("test");
			ResultSet rs = pm.executeQuery(sql);

			int count = rs.getMetaData().getColumnCount();
			String c = "C";
			for (int i = 1; i <= count; i++) {
				String name = rs.getMetaData().getColumnName(i);
				// ColumnConfig upric = new ColumnConfig("upric", "单价", 80);
				sbf.append("ColumnConfig " + (c + i) + " = new ColumnConfig(\""
						+ name + "\", \"" + name + "\", 80);\n");
				sbf.append("columns.add(" + (c + i) + ");\n");
			}
			sbf.append("\n");
			sbf.append("ColumnModel cm = new ColumnModel(columns);\n");
			sbf.append("grid = new BaseGrid(getStore(), cm);\n");
			sbf.append("cbs.setSelectionMode(SelectionMode.SINGLE);\n");

			sbf.append("grid.setSelectionModel(cbs);\n");
			sbf.append("return grid ;}\n");
			// ColumnModel cm = new ColumnModel(columns);
			// s_service_po_g_grid = new BaseGrid(s_service_po_g_store, cm)
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// CheckBoxSelectionModel cbs = new CheckBoxSelectionModel();
		// List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
		// columns.add(cbs.getColumn());

		// ColumnConfig upric = new ColumnConfig("upric", "单价", 80);

		return new String(sbf);
	}

	public String formGeneraration() {
		StringBuffer sbf = new StringBuffer();

		PoolMan pm = new PoolMan();
		sbf.append("BaseFormPanel form  =null;");
		sbf.append("\n");
		sbf.append("\n");
		sbf.append("BaseFormPanel createForm(){\n");
		sbf.append("BaseFormPanel form = new BaseFormPanel(getStore());");

		sbf.append("TableLayout tl = new TableLayout(4);\n");
		sbf.append("\n");
		sbf.append("TableData td = new TableData();\n");
		sbf.append("td.setRowspan(1);\n");
		sbf.append("td.setHorizontalAlign(HorizontalAlignment.LEFT);\n");
		sbf.append("td.setVerticalAlign(VerticalAlignment.TOP);\n");
		sbf.append("td.setPadding(2);\n");
		sbf.append("form.setLayout(tl);\n");
		sbf.append("form.setHeaderVisible(false);\n");
		sbf.append("\n");
		sbf.append("\n");
		sbf.append("\n");
		sbf.append("\n");
		try {
			pm.getPool("test");
			ResultSet rs = pm.executeQuery(sql);

			int count = rs.getMetaData().getColumnCount();
			String c = "C";
			for (int i = 1; i <= count; i++) {
				String name = rs.getMetaData().getColumnName(i);
				sbf.append("form.add(new Label(\"" + name + ":\"),td);\n");
				if (rs.getMetaData().getColumnClassName(i).equals(
						"java.sql.Timestamp")) {
					sbf.append(" DateField " + (c + "_data" + i)
							+ "  = new DateField(); \n");
					sbf
							.append((c + "_data" + i)
									+ ".getPropertyEditor().setFormat(DateTimeFormat.getFormat(\"yyyy-M-d\")); \n");
					sbf.append((c + "_data" + i) + ".setName(\"" + name
							+ "\");\n");
					sbf.append("form.add(" + (c + "_data" + i) + ",td);\n");
				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.math.BigDecimal")) {
					sbf.append(" NumberField " + (c + "_num" + i)
							+ "  = new NumberField(); \n");
					sbf.append((c + "_num" + i)
							+ ".setPropertyEditorType(Double.class); \n");
					sbf.append((c + "_num" + i) + ".setName(\"" + name
							+ "\");\n");
					sbf.append("form.add(" + (c + "_num" + i) + ",td);\n");

				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.Integer")) {
					sbf.append(" NumberField " + (c + "_num" + i)
							+ "  = new NumberField(); \n");
					sbf.append((c + "_num" + i)
							+ ".setPropertyEditorType(Integer.class); \n");
					sbf.append((c + "_num" + i) + ".setName(\"" + name
							+ "\");\n");
					sbf.append("form.add(" + (c + "_num" + i) + ",td);\n");
				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.Long")) {
					sbf.append(" NumberField " + (c + "_num" + i)
							+ "  = new NumberField(); \n");
					sbf.append((c + "_num" + i)
							+ ".setPropertyEditorType(Long.class); \n");
					sbf.append((c + "_num" + i) + ".setName(\"" + name
							+ "\");\n");
					sbf.append("form.add(" + (c + "_num" + i) + ",td);\n");
				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.String")) {
					sbf.append("TextField<String> " + (c + "_num" + i)
							+ "  = new TextField<String>(); \n");
					// sbf.append((c+"_num"+i)+".setPropertyEditorType(Long.class); \n");
					sbf.append((c + "_num" + i) + ".setName(\"" + name
							+ "\");\n");
					sbf.append("form.add(" + (c + "_num" + i) + ",td);\n");

				} else if (rs.getMetaData().getColumnClassName(i).equals(
						"java.lang.Boolean")) {

					sbf.append(" CheckBox " + (c + "_num" + i)
							+ "  = new CheckBox(); \n");
					// sbf.append((c+"_num"+i)+".setPropertyEditorType(Long.class); \n");
					sbf.append((c + "_num" + i) + ".setName(\"" + name
							+ "\");\n");
					sbf.append("form.add(" + (c + "_num" + i) + ",td);\n");
				} else {
					throw new RuntimeException("不支持的数据类型");
				}
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		sbf.append(" form.inited(); \n");
		sbf.append("return form;\n");
		sbf.append("};\n");
		sbf.append("\n");
		return new String(sbf);

	}

	/**
	 * 生成事件模板
	 * 
	 * @return
	 */
	public String ListenerGeneraration() {
		StringBuffer sbf = new StringBuffer();
		sbf
				.append("	int sync = 0;                                                      \n");
		sbf
				.append("	Listener<BaseEvent> defaultlistener;                               \n");
		sbf
				.append("                                                                     \n");
		sbf
				.append("	Listener<BaseEvent> getListener() {                                \n");
		sbf
				.append("		if(defaultlistener!=null)                                        \n");
		sbf
				.append("		{                                                                \n");
		sbf
				.append("			return defaultlistener;                                        \n");
		sbf
				.append("		}                                                                \n");
		sbf
				.append("                                                                     \n");
		sbf
				.append("		defaultlistener = new Listener<BaseEvent>() {                    \n");
		sbf
				.append("			public void handleEvent(BaseEvent be) {                        \n");
		sbf
				.append("				sync++;                                                      \n");
		sbf
				.append("				try {                                                        \n");
		sbf
				.append("					if (sync == 1) {                                           \n");
		sbf
				.append("						if (be.getType() == Events.Select) {                     \n");
		sbf
				.append("							if (be.getSource().equals( 按钮变量)) {                            \n");
		sbf
				.append("                                                                     \n");
		sbf
				.append("							}                                                      \n");
		sbf
				.append("						} else if (be.getType() == Events.Change) {              \n");
		sbf.append("							if (be.getSource().equals(输入型变量)) {         \n");
		sbf
				.append("                                                                     \n");
		sbf
				.append("							}                                                      \n");
		sbf
				.append("						} else if (be.getType() == Events.KeyUp) {               \n");
		sbf
				.append("							if (be instanceof ComponentEvent) {                    \n");
		sbf
				.append("								if (((ComponentEvent) be).getKeyCode() == 13) // 回车\n");
		sbf
				.append("								{                                                    \n");
		sbf
				.append("								}                                                    \n");
		sbf
				.append("							}                                                      \n");
		sbf
				.append("						}                                                        \n");
		sbf
				.append("					}                                                          \n");
		sbf
				.append("				} finally {                                                  \n");
		sbf
				.append("					sync--;                                                    \n");
		sbf
				.append("				}                                                            \n");
		sbf
				.append("			}                                                              \n");
		sbf
				.append("                                                                     \n");
		sbf
				.append("		};                                                               \n");
		sbf
				.append("		return defaultlistener;                                          \n");
		sbf
				.append("	}                                                                  \n");

		return new String(sbf);
	}

	String defaultEditor() {

		StringBuffer sbf = new StringBuffer();
		sbf
				.append("------------------------------------------------------------\n");
		sbf.append("//弹出式辅助录入，设定返回值，及选中后触发事件doposted，一般大量数据时候用，未设置分页\n");
		sbf
				.append("	List<ColumnConfig> bocodecolumns = new ArrayList<ColumnConfig>();           \n");
		sbf
				.append("	ColumnConfig service = new ColumnConfig(\"service\", \"服务类型\", 120);        \n");
		sbf
				.append("                                                                              \n");
		sbf
				.append("	bocodecolumns.add(service);                                                 \n");
		sbf
				.append("                                                                              \n");
		sbf
				.append("	ColumnConfig price = new ColumnConfig(\"price\", \"单价\", 100);                \n");
		sbf
				.append("	price.setAlignment(HorizontalAlignment.RIGHT);                              \n");
		sbf
				.append("	price.setNumberFormat(NumberFormat.getCurrencyFormat());                    \n");
		sbf
				.append("                                                                              \n");
		sbf
				.append("	bocodecolumns.add(price);                                                   \n");
		sbf
				.append("	ColumnConfig priceunit = new ColumnConfig(\"priceunit\", \"单位\", 50);         \n");
		sbf
				.append("                                                                              \n");
		sbf
				.append("	bocodecolumns.add(priceunit);                                               \n");
		sbf
				.append("	ModelType combotype = new ModelType();                                      \n");
		sbf
				.append("	combotype.setRoot(\"records\");                                               \n");
		sbf
				.append("	combotype.setRecordName(\"record\");                                          \n");
		sbf
				.append("	combotype.setTotalName(\"totle\");                                            \n");
		sbf
				.append("	                                                                            \n");
		sbf
				.append("	combotype.addField(\"service\");                                              \n");
		sbf
				.append("	combotype.addField(\"priceunit\");                                            \n");
		sbf
				.append("	combotype.addField(\"price\");                                                \n");
		sbf
				.append("	combotype.addField(\"bcode\");                                                \n");
		sbf
				.append("	StoreInfo comboinfo = new StoreInfo();                                      \n");
		sbf
				.append("	comboinfo.setTablename(\"s_service\");                                        \n");
		sbf
				.append("	comboinfo.setForcenolimit(\"true\");                                          \n");
		sbf
				.append("	comboinfo.setSql(\"select service,priceunit,price from s_service\");          \n");
		sbf
				.append("	BaseGridEditor bgeserviceitem = new BaseGridEditor(bocodecolumns, combotype,\n");
		sbf
				.append("			comboinfo, \"service\"){                                                  \n");
		sbf
				.append("	                                                                            \n");
		sbf
				.append("		public void doposted( ModelData modeldata) {                              \n");
		sbf
				.append("			service_qtyunit.setFireChangeEventOnSetValue(true);                     \n");
		sbf
				.append("			service_upric.setFireChangeEventOnSetValue(true);                       \n");
		sbf
				.append("			                                                                        \n");
		sbf
				.append("			service_qtyunit.setValue(\"\"+modeldata.get(\"priceunit\"));                \n");
		sbf
				.append("                                                                              \n");
		sbf
				.append("		                                                                          \n");
		sbf
				.append("			service_upric.setValue(Double.parseDouble(\"\"+modeldata.get(\"price\")));  \n");
		sbf
				.append("			service_qtyunit.setFireChangeEventOnSetValue(false);                    \n");
		sbf
				.append("			service_upric.setFireChangeEventOnSetValue(false);                      \n");
		sbf
				.append("		}                                                                         \n");
		sbf
				.append("	};                                                                          \n");
		sbf
				.append("------------------------------------------------------------\n");
		return new String(sbf);
	}

	public String RenderGeneraration() {
		StringBuffer sbf = new StringBuffer();
		sbf.append("grid的渲染------------------------\n");
		sbf
				.append("	public     void getRender(String column)                                                        \n");
		sbf
				.append("	{                                                                                               \n");
		sbf
				.append("		if(column.equals(\"bcode\"))                                                                    \n");
		sbf
				.append("		{                                                                                             \n");
		sbf
				.append("			final com.base.myproject.client.tools.GreetingServiceAsync greetingService = GWT            \n");
		sbf
				.append("			.create(com.base.myproject.client.tools.GreetingService.class);                             \n");
		sbf
				.append("			greetingService.getDataSet(\"select bcode,bname from bcode\",new AsyncCallback<DataSet>(){    \n");
		sbf
				.append("                                                                                                  \n");
		sbf
				.append("				@Override                                                                                 \n");
		sbf
				.append("				public void onFailure(Throwable caught) {                                                 \n");
		sbf
				.append("				Window.alert(\"网络连接错误\");                                                             \n");
		sbf
				.append("					                                                                                        \n");
		sbf
				.append("				}                                                                                         \n");
		sbf
				.append("                                                                                                  \n");
		sbf
				.append("				@Override                                                                                 \n");
		sbf
				.append("				public void onSuccess(final DataSet result) {                                             \n");
		sbf
				.append("					GridCellRenderer<ModelData>	renderer = new GridCellRenderer<ModelData>() {              \n");
		sbf
				.append("                                                                                                  \n");
		sbf
				.append("					      public String render(ModelData model, String property, ColumnData d, int rowIndex,\n");
		sbf
				.append("					          int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {             \n");
		sbf
				.append("					    	                                                                                  \n");
		sbf
				.append("					    	  for(int i=0;i<result.getRowCount();i++)                                         \n");
		sbf
				.append("					    	  {                                                                               \n");
		sbf
				.append("					    		  if(model.get(property)==null)                                                 \n");
		sbf
				.append("					    			  return model.get(property);                                                 \n");
		sbf
				.append("					    		  else if(model.get(property).equals(result.getValue(i, \"bcode\")))              \n");
		sbf
				.append("					    			  return result.getValue(i, \"bname\");                                         \n");
		sbf
				.append("					    	  }                                                                               \n");
		sbf
				.append("					    	  return model.get(property);                                                     \n");
		sbf
				.append("					      }                                                                                 \n");
		sbf
				.append("					    };                                                                                  \n");
		sbf
				.append("					    bcode.setRenderer(renderer)  ;                                                      \n");
		sbf
				.append("					    groupmenbergrid.getView().refresh(true);                                            \n");
		sbf
				.append("					                                                                                        \n");
		sbf
				.append("				}                                                                                         \n");
		sbf
				.append("				                                                                                          \n");
		sbf
				.append("			});                                                                                         \n");
		sbf
				.append("			                                                                                            \n");
		sbf
				.append("	                                                                                                \n");
		sbf
				.append("			                                                                                            \n");
		sbf
				.append("		}                                                                                             \n");
		sbf
				.append("		                                                                                              \n");
		sbf
				.append("	}                                                                                               \n");
		return sbf.toString();

	}

	public String getMutiSelectEditor() {
		StringBuffer sbf = new StringBuffer();
		sbf.append("多选对话框------------------------\n");
		sbf
				.append("List<ColumnConfig> bocodecolumns = new ArrayList<ColumnConfig>();\n");
		sbf
				.append("ColumnConfig service = new ColumnConfig(\"service\", \"服务类型\", 120);\n");

		sbf.append("bocodecolumns.add(service);\n");

		sbf
				.append("ColumnConfig price = new ColumnConfig(\"price\", \"单价\", 100);\n");
		sbf.append("	price.setAlignment(HorizontalAlignment.RIGHT);\n");
		sbf
				.append("	price.setNumberFormat(NumberFormat.getCurrencyFormat());\n");

		sbf.append("	bocodecolumns.add(price);\n");
		sbf
				.append("ColumnConfig priceunit = new ColumnConfig(\"priceunit\", \"单位\", 50);\n");

		sbf.append("bocodecolumns.add(priceunit);\n");
		sbf.append("ModelType combotype = new ModelType();\n");
		sbf.append("combotype.setRoot(\"records\");\n");
		sbf.append("combotype.setRecordName(\"record\");\n");
		sbf.append("combotype.setTotalName(\"totle\");\n");
		// combotype.addField("code", "service");
		sbf.append("combotype.addField(\"service\");\n");
		sbf.append("combotype.addField(\"priceunit\");\n");
		sbf.append("combotype.addField(\"price\");\n");
		sbf.append("combotype.addField(\"bcode\");\n");
		sbf.append("StoreInfo comboinfo = new StoreInfo();\n");
		sbf.append("comboinfo.setTablename(\"s_service\");\n");
		sbf.append("comboinfo.setForcenolimit(\"true\");\n");
		sbf
				.append("comboinfo.setSql(\"select service,priceunit,price from s_service\");\n");

		sbf
				.append("MutiSelectEditor m = new MutiSelectEditor(bocodecolumns,combotype,comboinfo,\"service\");\n");

		return sbf.toString();

	}

	public String getdefaultEditor()
	{
		StringBuffer sbf = new StringBuffer();
		sbf.append("//Grid的辅助录入\n");
		sbf
				.append("BaseComboBoxForm<BaseModelData> bsb2 = new BaseComboBoxForm<BaseModelData>(\"code\",\"desc_cn\",\"hr_Salary_Item\",\"\",true);\n");
		sbf.append("C3.setEditor(bsb2.getCelEditor());\n");

		sbf.append("C3.setRenderer(bsb2);\n");
						
		sbf.append("//Grid的 日期 辅助录入\n");
		sbf.append("	DateField C_data6 = new DateField(); \n");
		sbf.append("C_data6.getPropertyEditor().setFormat( \n");
		sbf.append("		DateTimeFormat.getFormat(\"yyyy-MM-dd\"));\n");
		sbf.append(" C6.setDateTimeFormat(DateTimeFormat.getFormat(\"yyyy-MM-dd\"));\n");
		 sbf.append(" C6.setEditor(new CellEditor(C_data6));\n");
		 
		 sbf.append(" //Grid的 下来  辅助录入 延时打开，无渲染\n");
		 sbf.append("  BaseComboBoxX bc3 = new BaseComboBoxX(\"name\",\"dictionary\", \"where type='hr_addrtype'\");\n");
		 sbf.append(" 		C3.setEditor(bc3.getCellEditor());\n");
		
		return sbf.toString();
	}

	public String getTablename() {
		return tablename;
	}

	public void setTablename(String tablename) {
		this.tablename = tablename;
	}

	public String getSql() {
		return sql;
	}

	public void setSql(String sql) {
		this.sql = sql;
	}

	public String[] getKey() {
		return key;
	}

	public void setKey(String[] key) {
		this.key = key;
	}

	/**
	 * @param argv
	 */
	public static void main2(String[] argv) {
		MakeStore ms = new MakeStore();
		ms.setSql("select * from dbo.prolongYearVacationRequest");
		ms.setKey(new String[] { "bcode", "year" });
		System.out.println(ms.Generation());
		System.out.println(ms.gridGeneraration());
		System.out.println(ms.formGeneraration());
		System.out.println(ms.ListenerGeneraration());
		System.out.println(ms.defaultEditor());
		System.out.println(ms.RenderGeneraration());
		System.out.println(ms.getdefaultEditor());

		//System.out.println(3/2+2%3);
		//		
		// String ss = "{dd}sss";
		// String m = "{dd}";
		// ss=ss.replaceAll(Pattern.quote(m), "aaa");
		// System.out.println("ss="+ss);

	}
	
	public static void main(String[] args) {
		JFrame jf = new JFrame();
		final TextArea ta = new TextArea("sadfasd");
		JButton getvalue = new JButton("转换");
		final JTextField jtf = new JTextField(20);
		ta.setRows(20);
		ta.setColumns(50);
		JLabel jl = new JLabel("要转换的字符串");
		jl.setLabelFor(jtf);

		jf.getContentPane().setLayout(new FlowLayout());
		jf.getContentPane().add(jl);
		jf.getContentPane().add(jtf);
		jf.getContentPane().add(ta);
		jf.getContentPane().add(getvalue);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		jf.setVisible(true);
		jf.setSize(640, 480);
		
		getvalue.addActionListener(new ActionListener(){
			@Override
			public void actionPerformed(ActionEvent e) {
				String variable = jtf.getText();
				StringBuilder newValue = new StringBuilder();
				String value = ta.getText();
				String[] values = value.split("\\r\\n");
				for (int i=0; i<values.length; i++) {
					newValue.append(variable);
					newValue.append(".append(\"");
					newValue.append(values[i].trim());
					newValue.append(" \");");
					newValue.append("\r\n");
				}
				ta.setText(newValue.toString());
			}
        });
	}
	
	public static void main1(String[] str) throws Exception
	{
		final PoolMan pm = new PoolMan();
	        Connection con = null;
	        con = pm.getPool("test");
	     //   pm.Update("");
	        
	        JFrame jf = new JFrame();
	       final TextArea ta = new TextArea("sadfasd");
	       JButton getvalue = new JButton("获取");
	        JButton jb = new JButton("提交（不能回退）");
	       final JTextField jtf = new JTextField(20);
	        //ta.setSize(640, 400);
	        ta.setRows(20);
	        ta.setColumns(50);
	        JLabel jl = new JLabel("关键字");
	        jl.setLabelFor(jtf);
	        
	        jf.getContentPane().setLayout(new FlowLayout());
	        jf.getContentPane().add(jl);
	        jf.getContentPane().add(jtf);
	        jf.getContentPane().add(ta);
	        jf.getContentPane().add(getvalue);
	        jf.getContentPane().add(jb);
	        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	        jf.setVisible(true);
	        jf.setSize(640,480);
	        
	        jb.addActionListener(new ActionListener(){

				@Override
				public void actionPerformed(ActionEvent e) {
					try {
						String value = ta.getText();
						value=value.replaceAll("'", "''");
						System.out.println(value);
						pm.Update("update sqltable set sqlvalue='"+value+"' where name='"+jtf.getText()+"'");
					} catch (Exception e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
					
				}
	        	
	        });
	        
	        getvalue.addActionListener(new ActionListener(){

				@Override
				public void actionPerformed(ActionEvent e) {
					
				String jtfstr = jtf.getText();
				ResultSet rs;
				try {
					rs = pm
							.executeQuery("select sqlvalue from sqltable where name='"
									+ jtfstr + "'");

					if (rs.next()) {
						ta.setText(rs.getString("sqlvalue"));
					}

					else {
						ta.setText("没有获得数据");
					}
				} catch (Exception e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
					
				}
	        	
	        });
	        
	        
	        
	}
}
